package com.wc.算法提高课.A第一章_动态规划.状态机模型.设计密码;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/10 21:58
 * @description https://www.acwing.com/problem/content/1054/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 55, P = (int) 1e9 + 7;
    static char[] t;
    static int[] ne = new int[N];
    // f[i][j] 表示原来的字母第i个跳到了模式串的第j的字符的方案数
    static int[][] f = new int[N][N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        t = (" " + sc.next()).toCharArray();
        int m = t.length - 1;
        // 计算ne
        for (int i = 2, j = 0; i <= m; i++) {
            while (j > 0 && t[i] != t[j + 1]) j = ne[j];
            if (t[i] == t[j + 1]) j++;
            ne[i] = j;
        }
        f[0][0] = 1;
        // 匹配
        for (int i = 1; i <= n; i++) {
            // 假设已经匹配了j个
            for (int j = 0; j < m; j++) {
                // 主串的第i个是什么
                for (int k = 'a'; k <= 'z'; k++) {
                    // 从这个位置开始匹配的
                    int u = j;
                    while (u > 0 && k != t[u + 1]) u = ne[u];
                    if (k == t[u + 1]) u++;
                    // 如果说没有匹配到最后一个,也就说明可以从前一个状态的第u个走不过来
                    if (u < m) f[i][u] = (f[i][u] + f[i - 1][j]) % P;
                }
            }
        }
        int res = 0;
        for (int i = 0; i < m; i++) res = (res + f[n][i]) % P;
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
